package com.qf.service.impl;

import com.qf.entity.Department;
import com.qf.entity.SystemMnue;
import com.qf.mapper.DeptMapper;
import com.qf.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 2019/11/29
 * 郭程鹏
 * gcp1909
 * 面向代码面向君,不负时光不负卿
 */
@Service
public class DeptImpl implements DeptService {
    @Resource
    private DeptMapper deptMapper;
    @Override
    public List<Department> allDept() {
        List<Department> depts = deptMapper.allDept();

        List<Department> first=new ArrayList<>();
        for (Department dept : depts) {
            if (dept.getSuperDept().equals("0")){
                //每次创建一个二级的部门
                ArrayList<Department> secondDept = new ArrayList<>();
                for (Department secDept : depts) {
                    if (secDept.getSuperDept().equals(dept.getDeptCode())){
                        secondDept.add(secDept);
                    }
                }
                dept.setSecondDept(secondDept);

                first.add(dept);
            }
        }
        return first;
    }
}
